//
//  ViewController.swift
//  KCSelectImage
//
//  Created by zhangjie579 on 09/01/2017.
//  Copyright (c) 2017 zhangjie579. All rights reserved.
//

import UIKit
import KCSelectImage

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        view.addSubview(photoView)
        view.addSubview(selectImage)
    }

    fileprivate lazy var photoView: KcPhotoView = {
        let photoView = KcPhotoView()
        photoView.arrayIcon = ["http://ww2.sinaimg.cn/bmiddle/904c2a35jw1emu3ec7kf8j20c10epjsn.jpg",
                               "http://ww2.sinaimg.cn/bmiddle/98719e4agw1e5j49zmf21j20c80c8mxi.jpg",
                               "http://ww2.sinaimg.cn/bmiddle/67307b53jw1epqq3bmwr6j20c80axmy5.jpg",
                               "http://ww2.sinaimg.cn/bmiddle/9ecab84ejw1emgd5nd6eaj20c80c8q4a.jpg",
                               "http://ww2.sinaimg.cn/bmiddle/642beb18gw1ep3629gfm0g206o050b2a.gif",
                               "http://ww1.sinaimg.cn/bmiddle/9be2329dgw1etlyb1yu49j20c82p6qc1.jpg",
                               "http://7xpu18.com1.z0.glb.clouddn.com/lvuUKXxCYA0l_V7v0yHpahe5ylJv"
        ]
        let w = KcPhotoView.getHeight((photoView.arrayIcon?.count)!)
        photoView.frame = CGRect(x: 0, y: 50, width: UIScreen.main.bounds.size.width, height: w)
        return photoView
    }()
    
    fileprivate lazy var selectImage: KcSelectImageShowView = {
        let h = KcSelectImageShowView.getHeight(UIScreen.main.bounds.size.width, array: nil, maxImagesCount: 9)
        let select = KcSelectImageShowView(CGRect(x: 0, y: 50, width: UIScreen.main.bounds.size.width, height: h), viewController: self, maxImagesCount: 9)
        select.delegate = self
        return select
    }()
}

extension ViewController: KcSelectImageShowViewDelegate {
    func kcSelectImageShowView(_ selectImageView: KcSelectImageShowView, finishImageArray: [UIImage]?, contentHeight: CGFloat) {
        selectImage.frame = CGRect(x: 0, y: 50, width: UIScreen.main.bounds.size.width, height: contentHeight)
    }
}

